home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2550 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  77 lines

  1. Newsgroups: comp.lang.c++
  2. Path: oasis.enmu.edu!cashew!reinholj
  3. From: reinholj@math.enmu.edu (John Reinhold)
  4. Subject: BORLAND C++ 4.5 wont add .1 and .9
  5. Sender: news@oasis.enmu.edu (All The News Fit To Print)
  6. Message-ID: <1996Jan18.044900.10609@oasis.enmu.edu>
  7. Date: Thu, 18 Jan 1996 04:49:00 GMT
  8. Organization: Eastern New Mexico University
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Borland C++ 4.5 won't add .1 + .9 to get 1.0
  12. This also does not work with negative numbers...
  13.  
  14. Look at my source code, see if you see the problem.
  15.  
  16. This all works unless you enter .01 or -.01,
  17. then it comes up with 0 and 0 which is incorrect.
  18.  
  19. begin code:------------
  20. #include <stdio.h>
  21.  
  22.  
  23. float x = 0.0,rnd = 0.9;
  24. int ceiling = 0, floor = 0;
  25.  
  26.  
  27. main ()
  28. {
  29.       /* */
  30.       printf("Enter a number (n.n) EX: 4.5 \n");
  31.       scanf("%f",&x);
  32.  
  33.       if (x<0.0)
  34.       {
  35.             ceiling=x;
  36.             floor=x-rnd;
  37.       }
  38.       else
  39.       {
  40.             ceiling=x+rnd;
  41.             floor=x;
  42.       }
  43.  
  44.       printf("\n\nCeiling of %f is %d",x,ceiling);
  45.       printf("\nFloor of %f is %d\n",x,floor);
  46.  
  47.       return 0;
  48.  
  49.  
  50. }
  51.  
  52.  
  53. end code:---------
  54.  
  55. this program is supposed to find the ceiling and floor of a number...
  56. i.e. the ceiling of 1.5 is 2, and the floor is 1.
  57.      the ceiling of -1.5 is -1 the floor is -2.
  58.  
  59. The ceiling is right on the number line, floor is left.
  60.  
  61. Thanks for any suggestions.
  62. By the way, making rnd 0.99 works (but only up to 1 decimal place).
  63.  
  64. -john
  65.  
  66. --
  67. ----------------------------<*>----------------------------
  68.                          TEAM OS/2
  69.           At WARP speed, Windows should not be open.
  70.  
  71.            OAKLAND RAIDERS      REAL MEN WEAR BLACK
  72. ++++++++++++++++++++++++++++<:>++++++++++++++++++++++++++++
  73. reinholj@mnw.net              Montgomery, Alabama USA
  74. reinholj@math.enmu.edu        Portales, New Mexico USA
  75. No Constitution, No Freedom.  SUPPORT THE BILL OF RIGHTS.
  76.                               (NOT the Bill of Gates!)
  77.